package de.nordakademie.wpk.share.ui.provider;

import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.Viewer;

import de.nordakademie.wpk.share.core.data.treeitem.TreeItem;

/**
 * @author Benedikt Stemmildt
 * 
 */
public class TreeContentProvider implements ITreeContentProvider {

	@Override
	public void dispose() {
	}

	@Override
	public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
	}

	@Override
	public Object[] getElements(Object inputElement) {
		TreeItem item = (TreeItem) inputElement;
		return item.getChildren().toArray();
	}

	@Override
	public Object[] getChildren(Object parentElement) {
		TreeItem item = (TreeItem) parentElement;
		return item.getChildren().toArray();
	}

	@Override
	public Object getParent(Object element) {
		TreeItem item = (TreeItem) element;
		return item.getParent();
	}

	@Override
	public boolean hasChildren(Object element) {
		TreeItem item = (TreeItem) element;
		return item.getChildren().size() > 0;
	}

}
